//
//  UIDevice+XYValue.m
//  UITest
//
//  Created by yao zhaofeng on 2022/11/2.
//  Copyright © 2022 YaoZhaofeng. All rights reserved.
//

#import "UIDevice+SafeArea.h"

@implementation UIDevice (SafeArea)

//安全区距顶部高度
+ (CGFloat)xy_safeAreaTop {
    if(@available(iOS 13.0, *)) {
        NSSet *scenes = [UIApplication sharedApplication].connectedScenes;
        UIWindowScene *scene = [scenes anyObject];
        UIWindow *window = scene.windows.firstObject;
        return window.safeAreaInsets.top;
    } else if (@available(iOS 11.0, *)) {
        UIWindow *window = [UIApplication sharedApplication].windows.firstObject;
        return window.safeAreaInsets.top;
    }
    
    return 0;
}

//安全区距底部高度
+ (CGFloat)xy_safeAreaBottom {
    if(@available(iOS 13.0, *)) {
        NSSet *scenes = [UIApplication sharedApplication].connectedScenes;
        UIWindowScene *scene = [scenes anyObject];
        UIWindow *window = scene.windows.firstObject;
        return window.safeAreaInsets.bottom;
    } else if (@available(iOS 11.0, *)) {
        UIWindow *window = [UIApplication sharedApplication].windows.firstObject;
        return window.safeAreaInsets.bottom;
    }
    
    return 0;
}

//状态栏高度
+ (CGFloat)xy_statusBarHeight {
    if(@available(iOS 13.0, *)) {
        NSSet *scenes = [UIApplication sharedApplication].connectedScenes;
        UIWindowScene *scene = [scenes anyObject];
        UIStatusBarManager *statusManager = scene.statusBarManager;
        return statusManager.statusBarFrame.size.height;
    } else {
        return [UIApplication sharedApplication].statusBarFrame.size.height;
    }
}

+ (CGFloat)xy_navigatorBarHeight {
    return 44;
}

+ (CGFloat)xy_tabbarHeight {
    return 49;
}

@end
